<?php
//echo base64_encode(file_get_contents("./pic/1.gif"));exit;
if(empty($_POST["code_row"]) || empty($_POST["system_id"]))
	echo "need post code_row and system_id";exit;

$codeRow  = $_POST["code_row"];
$systemId = $_POST["system_id"];
$systemNameHash = ["1"=>"nr","2"=>"zf","3"=>"hw"];
$systemName = isset($systemNameHash[$systemId])?$systemNameHash[$systemId]:"ot";

$fileName = time().$systemId.rand(1000,9999);
file_put_contents("./pic/$fileName.gif",base64_decode(substr($codeRow, 22)));

if($systemName == "nr"){
	$cmd = system("python nr_process.py ./pic/$fileName.gif ./pic/$fileName.gif",$ret);
	$cmd = system("/usr/bin/tesseract ./pic/$fileName.gif ./txt/$fileName -l eng -psm 7 digits nobatch",$ret);

}else if($systemName == "zf"){
	$cmd = system("python zf_process/code.py ./pic/$fileName.gif ./txt/$fileName.txt",$ret);

}else{
	$cmd = system("/usr/bin/tesseract ./pic/$fileName.gif ./txt/$fileName -l eng -psm 7 digits nobatch",$ret);
}

$code = file_get_contents("./txt/$fileName.txt");
$code = str_replace([" ","　","\t","\n","\r"],["","","","",""],$code);
echo $code;

unlink("./pic/$fileName.gif");
unlink("./txt/$fileName.txt");
